package com.example.administrator.yunniuusedcar.holder;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.common.ui.BaseAdapterRV;
import com.example.administrator.common.ui.BaseHolderRV;
import com.example.administrator.yunniuusedcar.MainActivity;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.activity.CommodityDetailsActivity;
import com.example.administrator.yunniuusedcar.model.mode_benn.ZgEquatorCar_JiaGe_Bean;
import com.squareup.picasso.Picasso;

import java.util.List;

/** 中规豪车  价格优先
 * Created by USER2015 on 2017/12/24.
 */

public class ZGjiaGeHolder extends BaseHolderRV<ZgEquatorCar_JiaGe_Bean> {
    private final List<ZgEquatorCar_JiaGe_Bean> listData;
    private ImageView ivHomeCarPage;
    private TextView tvHomeCatInfo;
    private TextView tvZGCarYhMoney;
    private TextView tvHomeCarPay;
    private TextView itemHomeCarSCsave;
    private TextView tvHomeCarMoney;

    /**
     * 构造方法
     *
     * @param context     上下文对象
     * @param parent      指RecyclerView控件
     * @param adapter     适配器
     * 3@param layoutResId RecyclerView的一个item布局文件
     */
    public ZGjiaGeHolder(Context context, ViewGroup parent, BaseAdapterRV<ZgEquatorCar_JiaGe_Bean> adapter, List<ZgEquatorCar_JiaGe_Bean>listData) {
        super(context, parent, adapter, R.layout.fragment_zonghepaixu);
        this.listData = listData;
    }

    @Override
    public void onFindViews(View itemView) {

        ivHomeCarPage = itemView.findViewById(R.id.iv_home_carPage);
        tvHomeCatInfo = itemView.findViewById(R.id.tv_home_catInfo);
        tvZGCarYhMoney = itemView.findViewById(R.id.tv_ZG_carYhMoney);
        tvHomeCarPay = itemView.findViewById(R.id.tv_home_carPay);
        itemHomeCarSCsave = itemView.findViewById(R.id.item_home_carSCsave);
        tvHomeCarMoney = itemView.findViewById(R.id.tv_home_carMoney);

    }

    @Override
    protected void onRefreshView(ZgEquatorCar_JiaGe_Bean bean, int position) {

        Picasso.with(context)
                .load(bean.data.get(position).logo).placeholder(R.drawable.jiazai)
                .into(ivHomeCarPage);      ///   hd : bean ??  汽车图片
        tvHomeCatInfo.setText(bean.data.get(position).name);    // 汽车名称
        tvZGCarYhMoney.setText("￥"+bean.data.get(position).integral_range +"万");//优惠价格
        tvHomeCarMoney.setText("市场价格:￥" + bean.data.get(position).market_price + "万");    //市场价
        //后台待给 付款/销售量
        tvHomeCarPay.setText("付款:" + bean.data.get(position).sale);
        itemHomeCarSCsave.setText("收藏: " + bean.data.get(position).collection_num);     // 收藏数量

    }

    @Override
    protected void onItemClick(View itemView, int position, ZgEquatorCar_JiaGe_Bean bean) {
        super.onItemClick(itemView, position, bean);

        listData.get(position);   //????//

        int ZgJgCarID =  bean.data.get(position).car_id ;

        Intent intent = new Intent(MainActivity.mactivity, CommodityDetailsActivity.class);   // 商品详情
        intent.putExtra("RanCarid",ZgJgCarID);

        MainActivity.mactivity.startActivity(intent);

    }
}
